home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2510.ZIP / TRSOURCE.EXE / _TR_FILE.ASM < prev    next >
Assembly Source File  |  1990-10-22  |  10KB  |  354 lines

  1. ;  _TR_FILE.ASM
  2. ;
  3. ;  by Leonard Zerman, Ralph Davis
  4. ;
  5. ; Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  6. ;
  7.  
  8.           PUBLIC __TR_OPEN,   __TR_CREAT,  __TR_READ
  9.           PUBLIC __TR_WRITE,  __TR_LSEEK,  __TR_CLOSE
  10.           PUBLIC __TR_RENAME, __TR_UNLINK, __TR_TELL
  11. ;***************************************************************
  12. ;
  13. ; This file contains TR-LIB file handling routines
  14. ; designed to be compatible with C's low level
  15. ; file handling functions.
  16. ;
  17. ; Functions included (and their equivalent C function):
  18. ;
  19. ;     __TR_OPEN     open(filename, mode);
  20. ;     __TR_CREAT    creat(filename, file_attribute);
  21. ;     __TR_READ     read(file_descriptor, destination, length);
  22. ;     __TR_WRITE    write(file_descriptor, source, length);
  23. ;     __TR_CLOSE    close(file_descriptor);
  24. ;     __TR_LSEEK    lseek(file_descriptor, offset, seek_mode);
  25. ;     __TR_RENAME   rename(old_filename,new_filename);
  26. ;     __TR_UNLINK   unlink(filename);
  27. ;
  28. ; Also included (with no low-level C equivalent):
  29. ;
  30. ;     __TR_TELL     corresponds to ftell(file_pointer);
  31. ;                  /* uses file_descriptor instead */
  32. ;
  33. ;****************************************************************
  34.  
  35. ;****************************************************************
  36. _TR_FILE_TEXT SEGMENT  BYTE PUBLIC 'CODE'
  37.          ASSUME   CS:_TR_FILE_TEXT
  38. ;-------------------------------------------------
  39.  
  40. ;     file_descriptor = __tr_open(filename, mode)
  41. ;
  42. ;        int file_descriptor;
  43. ;        char *filename;
  44. ;        int mode;
  45. ;
  46. ;        Returns:  DOS file handle if successful, -1 if not.
  47. ;
  48. ;----------
  49. __TR_OPEN  PROC    FAR
  50.           PUSH    BP
  51.           MOV     BP,SP
  52.           PUSH    BX
  53.           PUSH    DX
  54.           PUSH    DS
  55.           LDS     DX,[BP+6]       ; Get filename address
  56.           MOV     AX,[BP+10]      ; Get open mode
  57.           MOV     AH,3DH
  58.           INT     21H
  59.           JNC     _TR_OPEN_EXIT   ; File descriptor is in AX
  60.           XOR     AX,AX           ; Return -1 if error
  61.           DEC     AX
  62. _TR_OPEN_EXIT:
  63.           POP     DS
  64.           POP     DX
  65.           POP     BX
  66.           POP     BP
  67.           RET
  68. __TR_OPEN  ENDP
  69. ;------------------------------------------------
  70. ;
  71. ;     file_descriptor = __tr_creat(filename, file_attribute)
  72. ;
  73. ;        int file_descriptor;
  74. ;        char *filename;
  75. ;        int file_attribute;
  76. ;
  77. ;        Returns:  DOS file handle if successful, -1 if not.
  78. ;
  79. ;     File attributes are defined in TRLIB.H as follows:
  80. ;
  81. ;            #define FL_NORMAL  0
  82. ;            #define FL_RDONLY  1
  83. ;            #define FL_HIDDEN  2
  84. ;            #define FL_SYSTEM  4
  85. ;            #define FL_ARCHIVE 0x20
  86. ;
  87. ; NOTE:  This syntax differs slightly from C syntax.
  88. ;        C specifies that the second argument is the privilege
  89. ;        mode of the file.  DOS function 3CH, which
  90. ;        this function uses, expects the second argument
  91. ;        to be the file attribute (read-only, system, hidden,
  92. ;        normal, etc.).
  93. ;
  94. ;----------------
  95. __TR_CREAT PROC    FAR
  96.           PUSH    BP
  97.           MOV     BP,SP
  98.           PUSH    BX
  99.           PUSH    DX
  100.           PUSH    DS
  101.           LDS     DX,[BP+6]       ; Get filename address
  102.           MOV     CX,[BP+10]      ; Get file attribute
  103.           MOV     AH,3CH
  104.           INT     21H
  105.           JNC     _TR_CREAT_EXIT  ; AX contains file descriptor
  106.           XOR     AX,AX
  107.           DEC     AX              ; return -1 if error
  108. _TR_CREAT_EXIT:
  109.           POP     DS
  110.           POP     DX
  111.           POP     BX
  112.           POP     BP
  113.           RET
  114. __TR_CREAT  ENDP
  115. ;------------------------------------------------
  116. ;
  117. ;     status = _tr_read(file_descriptor, destination, length);
  118. ;
  119. ;        int status;
  120. ;        int file_descriptor;
  121. ;        char *destination;
  122. ;        int length;
  123. ;
  124. ;        Returns:  number of bytes read if successful, -1 if not.
  125. ;
  126. ;--------------
  127. __TR_READ PROC     FAR
  128.          PUSH     BP
  129.          MOV      BP,SP
  130.          PUSH     BX
  131.          PUSH     CX
  132.          PUSH     DX
  133.          PUSH     DS
  134.          MOV      BX,[BP+6]   ; get file descriptor
  135.          LDS      DX,[BP+8]   ; get address of buffer
  136.          MOV      CX,[BP+12]  ; get number of bytes to read
  137.          MOV      AH,3FH
  138.          INT      21H         
  139.          JNC      _TR_READ_EXIT   ; AX contains number of bytes read 
  140.          XOR      AX,AX       ; Return -1 for error
  141.          DEC      AX
  142. _TR_READ_EXIT:
  143.          POP      DS
  144.          POP      DX
  145.          POP      CX
  146.          POP      BX
  147.          POP      BP
  148.          RET 
  149. __TR_READ ENDP
  150. ;------------------------------------------------------
  151. ;
  152. ;     status = __tr_write(file_descriptor, source, length);
  153. ;
  154. ;        int status;
  155. ;        int file_descriptor;
  156. ;        char *source;
  157. ;        int length;
  158. ;
  159. ;        Returns:  number of bytes written, -1 if error.
  160. ;
  161. ;-----------
  162. __TR_WRITE PROC     FAR
  163.          PUSH     BP
  164.          MOV      BP,SP
  165.          PUSH     BX
  166.          PUSH     CX
  167.          PUSH     DX
  168.          PUSH     DS
  169.          MOV      BX,[BP+6]   ; get file descriptor
  170.          LDS      DX,[BP+8]   ; get address of buffer
  171.          MOV      CX,[BP+12]  ; get number of bytes to write
  172.          MOV      AH,40H
  173.          INT      21H
  174.          JNC      _TR_WRITE_EXIT  ; AX contains number of bytes written
  175.          XOR      AX,AX       ; return -1 for error
  176.          DEC      AX
  177.  _TR_WRITE_EXIT:
  178.          POP      DS
  179.          POP      DX
  180.          POP      CX
  181.          POP      BX
  182.          POP      BP
  183.          RET      
  184. __TR_WRITE ENDP
  185. ;------------------------------------------------------
  186. ;
  187. ;     status = _tr_close(file_descriptor);
  188. ;
  189. ;        int status;
  190. ;        int file_descriptor;
  191. ;
  192. ;        Returns:  0 if successful, -1 if not.
  193. ;
  194. ;------------
  195. __TR_CLOSE  PROC   FAR
  196.           PUSH   BP
  197.           MOV    BP,SP
  198.           PUSH   BX
  199.           MOV    BX,[BP+6]        ; get file descriptor
  200.           MOV    AH,3EH
  201.           INT    21H
  202.           JNC    _TR_CLOSE_GOOD
  203.           XOR    AX,AX
  204.           DEC    AX
  205.           JMP    SHORT _TR_CLOSE_EXIT
  206. _TR_CLOSE_GOOD:
  207.           XOR    AX,AX           ; return 0 if successful
  208. _TR_CLOSE_EXIT:
  209.           POP    BX
  210.           POP    BP
  211.           RET    
  212. __TR_CLOSE  ENDP
  213. ;---------------------------------------------
  214. ;
  215. ;     position = _tr_lseek(file_descriptor, offset, seek_mode);
  216. ;
  217. ;        long position;
  218. ;        int  file_descriptor;
  219. ;        long offset;
  220. ;        int  seek_mode;
  221. ;
  222. ;        Returns:  New file position if successful, -1L if not.
  223. ;
  224. ;----------
  225. __TR_LSEEK PROC     FAR
  226.          PUSH     BP
  227.          MOV      BP,SP
  228.          PUSH     CX
  229.          PUSH     DS
  230.          PUSH     SI
  231.          MOV      BX,[BP+6]   ; get file handle
  232.          MOV      DX,[BP+8]   ; get low word of seek offset
  233.          MOV      CX,[BP+10]  ; get high word of seek offset
  234.          MOV      AL,[BP+12]  ; get offset mode
  235.          MOV      AH,42H
  236.          INT      21H
  237.          JNC      _TR_LSEEK_GOOD  ; DX:AX contains new file position
  238.          MOV      DX,0FFFFH   ; return -1L for error
  239.          MOV      AX,0FFFFH
  240.          JMP      SHORT _TR_LSEEK_EXIT
  241. _TR_LSEEK_GOOD:
  242. _TR_LSEEK_EXIT:
  243.          POP      SI
  244.          POP      DS
  245.          POP      CX
  246.          POP      BP
  247.          RET      
  248. __TR_LSEEK ENDP
  249. ;------------------------------------------------------
  250. ;
  251. ;     position = _tr_tell(file_descriptor);
  252. ;
  253. ;        long position;
  254. ;        int  file_descriptor;
  255. ;
  256. ;        Returns:  Current file position if successful, -1L if not.
  257. ;
  258. ;------------
  259. __TR_TELL PROC     FAR
  260.          PUSH     BP
  261.          MOV      BP,SP
  262.          PUSH     CX
  263.          PUSH     DS
  264.          PUSH     SI
  265.          MOV      BX,[BP+6]   ; get file handle
  266.          MOV      AL,1        ; seek from current location
  267.          XOR      DX,DX       ; seek 0 bytes
  268.          XOR      CX,CX
  269.          MOV      AH,42H
  270.          INT      21H
  271.          JNC      _TR_TELL_GOOD  ; DX:AX contains new file position
  272.          MOV      DX,0FFFFH   ; return -1L for error
  273.          MOV      AX,0FFFFH
  274.          JMP      SHORT _TR_TELL_EXIT
  275. _TR_TELL_GOOD:
  276. _TR_TELL_EXIT:
  277.          POP      SI
  278.          POP      DS
  279.          POP      CX
  280.          POP      BP
  281.          RET      
  282. __TR_TELL ENDP
  283. ;------------------------------------------------------
  284. ;
  285. ;     error = _tr_rename(old_filename,new_filename);
  286. ;
  287. ;        int error;
  288. ;        char *old_filename;
  289. ;        char *new_filename;
  290. ;
  291. ;        Returns:  0 if successful, -1 if not
  292. ;
  293. ;-------------
  294. __TR_RENAME PROC   FAR
  295.          PUSH     BP
  296.          MOV      BP,SP
  297.          PUSH     DS
  298.          PUSH     ES
  299.          PUSH     DX
  300.          PUSH     DI
  301.          LDS      DX,[BP+6]     ; get address of old filename
  302.          LES      DI,[BP+10]    ; get address of new filename
  303.          MOV      AH,56H
  304.          INT      21H
  305.          JNC      _TR_REN_GOOD
  306.          XOR      AX,AX         ; return -1 if error
  307.          DEC      AX
  308.          JMP      SHORT _TR_REN_EXIT
  309. _TR_REN_GOOD:
  310.          XOR      AX,AX         ; return 0 for successful execution
  311. _TR_REN_EXIT:
  312.          POP      DI
  313.          POP      DX
  314.          POP      ES
  315.          POP      DS
  316.          POP      BP
  317.          RET
  318. __TR_RENAME ENDP
  319. ;-------------------------------------------------------
  320. ;
  321. ;     error = _tr_unlink(filename);
  322. ;
  323. ;        int error;
  324. ;        char *filename;
  325. ;
  326. ;     Returns:  0 if successful, -1 if not.
  327. ;
  328. ;------------
  329. __TR_UNLINK PROC   FAR
  330.            PUSH   BP
  331.            MOV    BP,SP
  332.            PUSH   DS
  333.            PUSH   DX
  334.            LDS    DX,[BP+6]       ; get filename
  335.            MOV    AH,41H
  336.            INT    21H
  337.            JNC    _TR_UNLINK_GOOD
  338.            XOR    AX,AX           ; return -1 for error
  339.            DEC    AX
  340.            JMP    SHORT _TR_UNLINK_EXIT
  341. _TR_UNLINK_GOOD:
  342.            XOR    AX,AX
  343. _TR_UNLINK_EXIT:
  344.            POP    DX
  345.            POP    DS
  346.            POP    BP
  347.            RET
  348. __TR_UNLINK ENDP
  349. ;--------------------------------------------------------
  350. _TR_FILE_TEXT    ENDS
  351. ;******************************************************
  352.          END
  353.  
  354.